#include <iostream>
#include <algorithm>

using namespace std;

const int N = 5010, M = 2e5 + 10, INF = 0x3f3f3f3f;
int n, m;
struct node{
	int a, b, w;
	
}a[M];

int fa[N]; 

bool cmp(node& x, node& y)
{
	return x.w < y.w;
}

int find(int x)
{
	return x == fa[x] ? x : fa[x] = find(fa[x]);
}

int kruskal()
{
	int cnt = 0;
	int ret = 0;
	sort(a + 1, a + 1 + m, cmp);
	
	
	for(int i = 1; i <= m; i++)
	{
		int x = a[i].a, y = a[i].b, w = a[i].w;
		int fx = find(x), fy = find(y);
		if(fx != fy)
		{
			cnt++;
			ret += w;
			fa[fx] = fy;
		}
	}
	return cnt == n - 1 ? ret : INF;
}

int main()
{
	cin >> n >> m;
	for(int i = 1; i <= m; i++) cin >> a[i].a >> a[i].b >> a[i].w;
	for(int i = 1; i <= n; i++) fa[i] = i;
	
	int ret = kruskal();
	if(ret == INF) cout << "orz" << endl;
	else cout << ret << endl;
	return 0;
}

